import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { observer, inject } from "@tarojs/mobx-rn";
import { Form, View, Textarea, Input, Button } from "@tarojs/components-rn";
import { getRuntime } from "../../utils/common";
import servicesStyleSheet from "./services_styles";
var _styleSheet = servicesStyleSheet;

let Services = class Services extends Component {
  constructor() {
    super(...arguments);
    this.state = {
      publicationType: "2",
      description: '',
      contacts: '',
      phone: '',
      wechatNo: '',
      qqNo: '',
      address: '',
      loading: false,
      disabled: false,
      submitText: '立即提交'
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '提供服务' });
  }
  formSubmit(e) {
    const { homeStore } = this.props.stores;
    let { publicationType } = this.state;
    let { description, contacts, phone, wechatNo, qqNo, address } = e.detail.value;
    if (!description) {
      getRuntime().showToast('服务内容不能为空~');
      return;
    }
    if (!contacts) {
      getRuntime().showToast('联系人不能为空~');
      return;
    }
    if (!phone) {
      getRuntime().showToast('联系电话不能为空~');
      return;
    }
    this.setState({
      loading: true,
      disabled: true,
      submitText: '数据提交中...'
    });
    homeStore.saveUserInfomations({
      form: {
        publicationType,
        description,
        contacts,
        phone,
        wechatNo,
        qqNo,
        address
      },
      callBack: () => {
        this.setState({
          loading: false,
          disabled: false,
          submitText: '立即发布'
        });
        getRuntime().showToast('数据提交成功,页面即将跳转~');
        setTimeout(() => {
          getRuntime().navigateTo('/pages/newest/index');
        }, 2000);
      }
    });
  }
  render() {
    let { loading, disabled, submitText } = this.state;
    return <View style={_styleSheet["from-wrap"]}>
        <Form onSubmit={this.formSubmit.bind(this)}>
          <View style={_styleSheet["input-group"]}>
            <Textarea placeholderClass="placeholder-class" placeholder="请填写您要提供的服务内容(必填)" maxlength={-1} name="description" style={_styleSheet["from-textarea"]} />
          </View>
          <View style={_styleSheet["interval"]} />
          <View style={[_styleSheet["item-group"], _styleSheet["pt0"], _styleSheet["pb0"]]}>
            <View style={_styleSheet["input-group"]}>
              <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>联系人</View>
              <Input placeholder="请填写联系人姓名" placeholderClass="placeholder_class" name="contacts" style={_styleSheet["from-input"]} />
            </View>

            <View style={_styleSheet["input-group"]}>
              <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>联系电话</View>
              <Input type={"number"} maxLength={11} placeholderClass="placeholder_class" placeholder="请填写联系电话" name="phone" style={_styleSheet["from-input"]} />
            </View>

            <View style={[_styleSheet["input-group"], _styleSheet["input-switch"]]}>
              <View style={_styleSheet["input-name"]}>微信号</View>
              <Input placeholderClass="placeholder_class" placeholder="请填写微信号" name="wechatNo" style={_styleSheet["from-input"]} />
            </View>

            <View style={_styleSheet["input-group"]}>
              <View style={_styleSheet["input-name"]}>QQ号</View>
              <Input type={"number"} maxLength={11} placeholderClass="placeholder_class" placeholder="请填写QQ号" name="qqNo" style={_styleSheet["from-input"]} />
            </View>
            <View style={_styleSheet["input-group"]}>
              <View style={_styleSheet["input-name"]}>联系地址</View>
              <Input placeholderClass="placeholder_class" placeholder="请填写联系地址" name="address" style={_styleSheet["from-input"]} />
            </View>
          </View>

          <Button formType="submit" loading={loading} disabled={disabled} style={_styleSheet["from-submit"]}>{submitText}</Button>
        </Form>
      </View>;
  }
};
Services = tslib_1.__decorate([inject("stores"), observer], Services);
export default Services;